<template>
  <div style="text-align: center">
    <van-nav-bar title="京东账户注册" left-arrow @click-left="onClickLeft" />

    <!-- //登陆表单 -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
        v-model="password1"
        type="password1"
        name="密码"
        label="确认密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请再次确认密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          round
          block
          type="info"
          color="linear-gradient(to right, #ff6034, #ee0a24)"
          native-type="submit"
          >注册</van-button
        >
      </div>
    </van-form>
  </div>
</template>
  
  <script>
import { Notify } from "vant";
export default {
  components: {
    [Notify.Component.name]: Notify.Component,
  },
  data() {
    return {
      username: "",
      password: "",
      password1: "",
    };
  },
  methods: {
    //注册
    onSubmit(values) {
      if (this.password == this.password1) {
        this.$http({
          url: "api/user/dofinishregister",
          method: "post",
          data: {
            tel: this.username,
            password: this.password,
          },
        }).then(
          (res) => {
            if (res.data.code === "200") {
              this.$router.push("/LoginPage");
            } else {
              console.log(res);
            }
          },
          (rej) => {
            console.log(rej);
          }
        );
      } else {
        Notify("两次密码不一致");
      }
    },
    //返回登录页面
    onClickLeft() {
      this.$router.push("/LoginPage");
    },
  },
};
</script>
  
  <style>
</style>